package com.ymatou.iapi.godmch.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.getChargeConfigBean;
import com.ymatou.iapi.godmch.parameter.setChargeConfigBean;
import com.ymatou.iapi.godmch.service.getChargeConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.chargeconfig;
import com.ymttest.database.model.godmch.chargeconfigExample;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
/**
*获取商户功能收费配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getChargeConfig{
	private static getChargeConfigBean bean;
	private static getChargeConfigCall call;
	
	DefGodMchWapper configMapper=new DefGodMchWapper();
	chargeconfigExample example=new chargeconfigExample();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商户功能收费配置");
	}

	@Before
	public void caseUp() {
		bean=new getChargeConfigBean();
		call=new getChargeConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getChargeConfig_001() {
		Logger.start(true,"正例-获取商户功能收费配置-独立小程序,互动直播都收费");
		try {
			
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setChargeConfigBean configBean=GodmchManageCallService.initSetChargeConfigBean(mchId);
			GodmchManageCallService.setChargeConfigCall(configBean);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			
			example.createCriteria().andMchIdEqualTo(mchId);
			chargeconfig config=configMapper.getChargeConfig(example).get(0);
			Logger.verifyEquals("200", new JSONObject(call.getReturnData()).get("status").toString(), "验证status");
			Logger.verifyEquals(new JSONObject(new JSONObject(call.getReturnData()).get("result").toString()).get("mchId").toString(), config.getMchId().toString(), "验证数据库chargeconfig 中的MchId");
			Logger.verifyEquals(new JSONObject(new JSONObject(call.getReturnData()).get("result").toString()).get("freeMiniApp").toString(), config.getWxApp().toString(), "验证数据库chargeconfig 中的WxApp");
			Logger.verifyEquals(new JSONObject(new JSONObject(call.getReturnData()).get("result").toString()).get("freeLive").toString(), config.getLiveVideo().toString(), "验证数据库chargeconfig 中的LiveVideo");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getChargeConfig_002() {
		Logger.start(true,"正例-获取商户功能收费配置-商户id不存在");
		try {
			
			bean.setMchId(11223344);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("200", new JSONObject(call.getReturnData()).get("status").toString(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getChargeConfig_003() {
		Logger.start(true,"正例-获取商户功能收费配置-独立小程序不免收费");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setChargeConfigBean configBean=GodmchManageCallService.initSetChargeConfigBean(mchId);
			configBean.setFreeMiniApp(false);
			GodmchManageCallService.setChargeConfigCall(configBean);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			
			example.createCriteria().andMchIdEqualTo(mchId);
			chargeconfig config=configMapper.getChargeConfig(example).get(0);
			Logger.verifyEquals("200", new JSONObject(call.getReturnData()).get("status").toString(), "验证status");
			Logger.verifyEquals(new JSONObject(new JSONObject(call.getReturnData()).get("result").toString()).get("mchId").toString(), config.getMchId().toString(), "验证数据库chargeconfig 中的MchId");
			Logger.verifyEquals(new JSONObject(new JSONObject(call.getReturnData()).get("result").toString()).get("freeMiniApp").toString(), config.getWxApp().toString(), "验证数据库chargeconfig 中的WxApp");
			Logger.verifyEquals(new JSONObject(new JSONObject(call.getReturnData()).get("result").toString()).get("freeLive").toString(), config.getLiveVideo().toString(), "验证数据库chargeconfig 中的LiveVideo");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getChargeConfig_004() {
		Logger.start(true,"正例-获取商户功能收费配置-互动直播不免收费");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setChargeConfigBean configBean=GodmchManageCallService.initSetChargeConfigBean(mchId);
			configBean.setFreeLive(false);
			GodmchManageCallService.setChargeConfigCall(configBean);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			
			example.createCriteria().andMchIdEqualTo(mchId);
			chargeconfig config=configMapper.getChargeConfig(example).get(0);
			Logger.verifyEquals("200", new JSONObject(call.getReturnData()).get("status").toString(), "验证status");
			Logger.verifyEquals(new JSONObject(new JSONObject(call.getReturnData()).get("result").toString()).get("mchId").toString(), config.getMchId().toString(), "验证数据库chargeconfig 中的MchId");
			Logger.verifyEquals(new JSONObject(new JSONObject(call.getReturnData()).get("result").toString()).get("freeMiniApp").toString(), config.getWxApp().toString(), "验证数据库chargeconfig 中的WxApp");
			Logger.verifyEquals(new JSONObject(new JSONObject(call.getReturnData()).get("result").toString()).get("freeLive").toString(), config.getLiveVideo().toString(), "验证数据库chargeconfig 中的LiveVideo");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}